<html>
<head><meta charset="utf-8"><title>global hooks and their relation to traits and vtables · t-lang · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/index.html">t-lang</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/global.20hooks.20and.20their.20relation.20to.20traits.20and.20vtables.html">global hooks and their relation to traits and vtables</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="211372160"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/global%20hooks%20and%20their%20relation%20to%20traits%20and%20vtables/near/211372160" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jane Lusby <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/global.20hooks.20and.20their.20relation.20to.20traits.20and.20vtables.html#211372160">(Sep 26 2020 at 18:08)</a>:</h4>
<p>This is kinda snowballing out of <a href="https://github.com/rust-lang/project-error-handling/issues/3">https://github.com/rust-lang/project-error-handling/issues/3</a> where  I'm doing research on moving Backtrace and Error into core to ensure we can stabilize it without backing ourselves in a corner</p>
<p>The current plan for doing so is to define some hooks in core like <code>panic_impl</code> that get defined in <code>std</code> and invoked by the <code>Backtrace</code> type which is moved to <code>core</code> to access its implementation details</p>



<a name="211372187"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/global%20hooks%20and%20their%20relation%20to%20traits%20and%20vtables/near/211372187" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jane Lusby <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/global.20hooks.20and.20their.20relation.20to.20traits.20and.20vtables.html#211372187">(Sep 26 2020 at 18:10)</a>:</h4>
<p>Its feeling more and more like traits and the adhoc hooks we're defining for stuff like the panic handler are sort of like universally quantified dynamic dispatch vs existentially quantified static dispatch (or maybe even const dynamic dispatch?)</p>



<a name="211372242"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/global%20hooks%20and%20their%20relation%20to%20traits%20and%20vtables/near/211372242" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jane Lusby <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/global.20hooks.20and.20their.20relation.20to.20traits.20and.20vtables.html#211372242">(Sep 26 2020 at 18:10)</a>:</h4>
<p>where with traits you can have many impls and each object carries its vtable and uses virtual function calls</p>



<a name="211372250"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/global%20hooks%20and%20their%20relation%20to%20traits%20and%20vtables/near/211372250" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jane Lusby <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/global.20hooks.20and.20their.20relation.20to.20traits.20and.20vtables.html#211372250">(Sep 26 2020 at 18:11)</a>:</h4>
<p>where as with hooks you have one statically defined implementor of the trait and all invocations of it are statically dispatched</p>



<a name="211372401"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/global%20hooks%20and%20their%20relation%20to%20traits%20and%20vtables/near/211372401" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jane Lusby <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/global.20hooks.20and.20their.20relation.20to.20traits.20and.20vtables.html#211372401">(Sep 26 2020 at 18:15)</a>:</h4>
<p>so for backtrace it would be nice if we had something like this</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="c1">// in core</span>
<span class="cp">#[existential]</span><span class="w"></span>
<span class="k">trait</span><span class="w"> </span><span class="n">Backtrace</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="c1">// ....</span>
<span class="p">}</span><span class="w"></span>
</code></pre></div>

<p><span class="user-mention" data-user-id="119009">@eddyb</span> notes:</p>
<blockquote>
<p>that's just a trait with orphan impls that still have to be coherent across a crate graph lmao</p>
</blockquote>



<a name="211372471"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/global%20hooks%20and%20their%20relation%20to%20traits%20and%20vtables/near/211372471" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jane Lusby <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/global.20hooks.20and.20their.20relation.20to.20traits.20and.20vtables.html#211372471">(Sep 26 2020 at 18:16)</a>:</h4>
<p>I don't think this should necessarily be done as a prerequisite for stabilizing backtrace but I thought I'd mention it</p>



<a name="211372615"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/global%20hooks%20and%20their%20relation%20to%20traits%20and%20vtables/near/211372615" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/global.20hooks.20and.20their.20relation.20to.20traits.20and.20vtables.html#211372615">(Sep 26 2020 at 18:20)</a>:</h4>
<p>in my experience, most proposals like this have gotten little traction and ended up in the RFC graveyard</p>



<a name="211372729"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/global%20hooks%20and%20their%20relation%20to%20traits%20and%20vtables/near/211372729" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/global.20hooks.20and.20their.20relation.20to.20traits.20and.20vtables.html#211372729">(Sep 26 2020 at 18:23)</a>:</h4>
<p>so I'd be wary of going this route without knowing a lot can be invested in it. I'd start with looking into lang team buy-in, etc.</p>



<a name="211372808"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/global%20hooks%20and%20their%20relation%20to%20traits%20and%20vtables/near/211372808" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/global.20hooks.20and.20their.20relation.20to.20traits.20and.20vtables.html#211372808">(Sep 26 2020 at 18:25)</a>:</h4>
<p>oh this is in t-lang, oops I missed that</p>



<a name="211372860"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/global%20hooks%20and%20their%20relation%20to%20traits%20and%20vtables/near/211372860" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/global.20hooks.20and.20their.20relation.20to.20traits.20and.20vtables.html#211372860">(Sep 26 2020 at 18:26)</a>:</h4>
<p>the advantage of using traits here is that it fits Rust better than trying to emulate some ML module system</p>



<a name="211372864"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/global%20hooks%20and%20their%20relation%20to%20traits%20and%20vtables/near/211372864" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jane Lusby <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/global.20hooks.20and.20their.20relation.20to.20traits.20and.20vtables.html#211372864">(Sep 26 2020 at 18:26)</a>:</h4>
<p>I do love traits</p>



<a name="211372886"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/global%20hooks%20and%20their%20relation%20to%20traits%20and%20vtables/near/211372886" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/global.20hooks.20and.20their.20relation.20to.20traits.20and.20vtables.html#211372886">(Sep 26 2020 at 18:27)</a>:</h4>
<p>so yeah cc <span class="user-mention" data-user-id="116009">@nikomatsakis</span>, curious what he thinks about using traits with intentional orphan impls (that are still coherent, even if enforced late in the crate graph, like lang items)</p>



<a name="211372895"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/global%20hooks%20and%20their%20relation%20to%20traits%20and%20vtables/near/211372895" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/global.20hooks.20and.20their.20relation.20to.20traits.20and.20vtables.html#211372895">(Sep 26 2020 at 18:27)</a>:</h4>
<p>actually is there a @ for wg-traits?</p>



<a name="211372936"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/global%20hooks%20and%20their%20relation%20to%20traits%20and%20vtables/near/211372936" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jane Lusby <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/global.20hooks.20and.20their.20relation.20to.20traits.20and.20vtables.html#211372936">(Sep 26 2020 at 18:28)</a>:</h4>
<p><span class="user-group-mention" data-user-group-id="692">@WG-traits</span></p>



<a name="211373228"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/global%20hooks%20and%20their%20relation%20to%20traits%20and%20vtables/near/211373228" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Nika Layzell <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/global.20hooks.20and.20their.20relation.20to.20traits.20and.20vtables.html#211373228">(Sep 26 2020 at 18:36)</a>:</h4>
<p>Another potential option (if we're interested in "existential traits") is to mark a specific impl as <code>#[existential]</code> instead. You'd write a coherent impl under the current framework, but with no implementation, and <code>#[existential]</code>. </p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="k">trait</span><span class="w"> </span><span class="n">MyTrait</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">  </span><span class="k">fn</span> <span class="nf">do_thing</span><span class="p">(</span><span class="o">&amp;</span><span class="bp">self</span><span class="p">);</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
<span class="cp">#[existential]</span><span class="w"></span>
<span class="k">impl</span><span class="w"> </span><span class="n">MyTrait</span><span class="w"> </span><span class="k">for</span><span class="w"> </span><span class="p">()</span><span class="w"> </span><span class="p">{}</span><span class="w"></span>
</code></pre></div>

<p>This would allow another crate, which can observe the <code>#[existential]</code> impl, to write an impl which would otherwise violate coherence, such as:</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="k">impl</span><span class="w"> </span><span class="n">MyTrait</span><span class="w"> </span><span class="k">for</span><span class="w"> </span><span class="p">()</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">  </span><span class="k">fn</span> <span class="nf">do_thing</span><span class="p">(</span><span class="o">&amp;</span><span class="bp">self</span><span class="p">)</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="n">println</span><span class="o">!</span><span class="p">(</span><span class="s">"hello!"</span><span class="p">);</span><span class="w"> </span><span class="p">}</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</code></pre></div>

<p>Rust would then enforce that exactly one non-<code>#[existential]</code> impl of <code>impl MyTrait for ()</code> exists in the crate graph while building. There _may_ need to be limitations on what is allowed on these impls, however, such as preventing associated types, constants, and/or generics, though I don't know enough to be sure.</p>



<a name="211380200"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/global%20hooks%20and%20their%20relation%20to%20traits%20and%20vtables/near/211380200" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jack Huey <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/global.20hooks.20and.20their.20relation.20to.20traits.20and.20vtables.html#211380200">(Sep 26 2020 at 20:01)</a>:</h4>
<p><span class="user-mention silent" data-user-id="220273">Jane Lusby</span> <a href="#narrow/stream/213817-t-lang/topic/global.20hooks.20and.20their.20relation.20to.20traits.20and.20vtables/near/211372936">said</a>:</p>
<blockquote>
<p><span class="user-group-mention" data-user-group-id="692">@WG-traits</span></p>
</blockquote>
<p>Unrelated, but it's surprising to me that I don't get pings for this</p>



<a name="211380265"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/global%20hooks%20and%20their%20relation%20to%20traits%20and%20vtables/near/211380265" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/global.20hooks.20and.20their.20relation.20to.20traits.20and.20vtables.html#211380265">(Sep 26 2020 at 20:02)</a>:</h4>
<p>should be fixed now</p>



<a name="211380278"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/global%20hooks%20and%20their%20relation%20to%20traits%20and%20vtables/near/211380278" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jack Huey <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/global.20hooks.20and.20their.20relation.20to.20traits.20and.20vtables.html#211380278">(Sep 26 2020 at 20:02)</a>:</h4>
<p>test?</p>



<a name="211381191"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/global%20hooks%20and%20their%20relation%20to%20traits%20and%20vtables/near/211381191" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jane Lusby <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/global.20hooks.20and.20their.20relation.20to.20traits.20and.20vtables.html#211381191">(Sep 26 2020 at 20:26)</a>:</h4>
<p><span class="user-group-mention" data-user-group-id="692">@WG-traits</span></p>



<a name="211381207"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/global%20hooks%20and%20their%20relation%20to%20traits%20and%20vtables/near/211381207" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jack Huey <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/global.20hooks.20and.20their.20relation.20to.20traits.20and.20vtables.html#211381207">(Sep 26 2020 at 20:27)</a>:</h4>
<p>That works, thanks!</p>



<a name="211392683"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/global%20hooks%20and%20their%20relation%20to%20traits%20and%20vtables/near/211392683" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Charles Lew <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/global.20hooks.20and.20their.20relation.20to.20traits.20and.20vtables.html#211392683">(Sep 27 2020 at 02:02)</a>:</h4>
<p>Another option: I'd love to see <a href="https://docs.rs/linkme">https://docs.rs/linkme</a> be promoted to a language feature. It's a crate that allows downstream crates to "inject" data into upstream crate defined collections.<br>
While that crate is using linker hacks and can only support <code>[T]</code> as collection, if we implement them within rustc, i'd imagine it would be quite easy to support <code>Option&lt;T&gt;</code> as collection, which will have the same effect as existential trait, and also useful in many ways.</p>



<a name="211434151"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/global%20hooks%20and%20their%20relation%20to%20traits%20and%20vtables/near/211434151" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> scottmcm <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/global.20hooks.20and.20their.20relation.20to.20traits.20and.20vtables.html#211434151">(Sep 27 2020 at 20:54)</a>:</h4>
<p>That was a popular topic in IRLO for a bit last year, but AFAIK didn't go anywhere at the language level:</p>
<ul>
<li><a href="https://internals.rust-lang.org/t/pre-rfc-add-language-support-for-global-constructor-functions/9840?u=scottmcm">https://internals.rust-lang.org/t/pre-rfc-add-language-support-for-global-constructor-functions/9840?u=scottmcm</a></li>
<li><a href="https://internals.rust-lang.org/t/idea-global-static-variables-extendable-at-compile-time/9879?u=scottmcm">https://internals.rust-lang.org/t/idea-global-static-variables-extendable-at-compile-time/9879?u=scottmcm</a></li>
</ul>



<a name="211786296"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/global%20hooks%20and%20their%20relation%20to%20traits%20and%20vtables/near/211786296" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/global.20hooks.20and.20their.20relation.20to.20traits.20and.20vtables.html#211786296">(Sep 30 2020 at 16:28)</a>:</h4>
<p>I am theoretically in favor of some design here</p>



<a name="211786327"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/global%20hooks%20and%20their%20relation%20to%20traits%20and%20vtables/near/211786327" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/global.20hooks.20and.20their.20relation.20to.20traits.20and.20vtables.html#211786327">(Sep 30 2020 at 16:28)</a>:</h4>
<p>I feel like it would theoretically make a nice project group</p>



<a name="211786344"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/global%20hooks%20and%20their%20relation%20to%20traits%20and%20vtables/near/211786344" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/global.20hooks.20and.20their.20relation.20to.20traits.20and.20vtables.html#211786344">(Sep 30 2020 at 16:28)</a>:</h4>
<p>Unlike other trait things, it's not really blocked on chalk or anything like <em>that</em></p>



<a name="211786385"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/global%20hooks%20and%20their%20relation%20to%20traits%20and%20vtables/near/211786385" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/global.20hooks.20and.20their.20relation.20to.20traits.20and.20vtables.html#211786385">(Sep 30 2020 at 16:29)</a>:</h4>
<p>My main concern would be getting the right folks and the question of it actually making progress -- I'd be reluctant to open a door like this unless we have confidence we can close it</p>



<a name="211787468"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/global%20hooks%20and%20their%20relation%20to%20traits%20and%20vtables/near/211787468" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/global.20hooks.20and.20their.20relation.20to.20traits.20and.20vtables.html#211787468">(Sep 30 2020 at 16:36)</a>:</h4>
<p>I would <em>love</em> to see a solution to this problem.</p>



<a name="211787493"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/global%20hooks%20and%20their%20relation%20to%20traits%20and%20vtables/near/211787493" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/global.20hooks.20and.20their.20relation.20to.20traits.20and.20vtables.html#211787493">(Sep 30 2020 at 16:36)</a>:</h4>
<p>I can think of a few of the right people. <span class="user-mention" data-user-id="128448">@stjepang</span> for instance.</p>



<a name="211787559"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/global%20hooks%20and%20their%20relation%20to%20traits%20and%20vtables/near/211787559" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/global.20hooks.20and.20their.20relation.20to.20traits.20and.20vtables.html#211787559">(Sep 30 2020 at 16:37)</a>:</h4>
<p>The idea of having trait-driven pseudo-global state makes sense.</p>



<a name="211794251"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/global%20hooks%20and%20their%20relation%20to%20traits%20and%20vtables/near/211794251" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jethro <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/global.20hooks.20and.20their.20relation.20to.20traits.20and.20vtables.html#211794251">(Sep 30 2020 at 17:30)</a>:</h4>
<p>there's already a trait-based design. <a href="https://github.com/rust-lang/rfcs/pull/2492">https://github.com/rust-lang/rfcs/pull/2492</a></p>



<a name="211798193"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/global%20hooks%20and%20their%20relation%20to%20traits%20and%20vtables/near/211798193" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/global.20hooks.20and.20their.20relation.20to.20traits.20and.20vtables.html#211798193">(Sep 30 2020 at 18:01)</a>:</h4>
<p>Looking now...</p>



<a name="211798373"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/global%20hooks%20and%20their%20relation%20to%20traits%20and%20vtables/near/211798373" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/global.20hooks.20and.20their.20relation.20to.20traits.20and.20vtables.html#211798373">(Sep 30 2020 at 18:03)</a>:</h4>
<p><span class="user-mention" data-user-id="138938">@Jethro</span> in answer to your question, I'd give it a solid <em>maybe</em> :)</p>



<a name="211798411"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/global%20hooks%20and%20their%20relation%20to%20traits%20and%20vtables/near/211798411" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/global.20hooks.20and.20their.20relation.20to.20traits.20and.20vtables.html#211798411">(Sep 30 2020 at 18:03)</a>:</h4>
<p>I guess tbh I'm still sort of inclined to keep it postponed whilst we pursue other things</p>



<a name="211798895"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/global%20hooks%20and%20their%20relation%20to%20traits%20and%20vtables/near/211798895" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/global.20hooks.20and.20their.20relation.20to.20traits.20and.20vtables.html#211798895">(Sep 30 2020 at 18:07)</a>:</h4>
<p>Looking through 2492, I personally feel it's close but there are additional bits I'd want to see.</p>



<a name="211799015"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/global%20hooks%20and%20their%20relation%20to%20traits%20and%20vtables/near/211799015" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/global.20hooks.20and.20their.20relation.20to.20traits.20and.20vtables.html#211799015">(Sep 30 2020 at 18:08)</a>:</h4>
<p>Short version: I'd like to have a mechanism to actually <em>handle</em> conflict in the crate graph. Specifically, I'd like a crate that's "higher" in the crate graph to be able to say "yeah, I know that something in my dependency tree says the type is X, but no, I'm overriding and saying the type is Y instead".</p>



<a name="211799108"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/global%20hooks%20and%20their%20relation%20to%20traits%20and%20vtables/near/211799108" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/global.20hooks.20and.20their.20relation.20to.20traits.20and.20vtables.html#211799108">(Sep 30 2020 at 18:09)</a>:</h4>
<p>Concretely: if A depends on B, and B depends on C and D, then if C and D both "provide" the type there's a compile error, but B can override and say "here's the type" and then there's no compile error (as long as the type meets the defined trait constraints).</p>



<a name="211800562"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/global%20hooks%20and%20their%20relation%20to%20traits%20and%20vtables/near/211800562" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jethro <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/global.20hooks.20and.20their.20relation.20to.20traits.20and.20vtables.html#211800562">(Sep 30 2020 at 18:22)</a>:</h4>
<p><span class="user-mention" data-user-id="220594">@John Ericson</span> assuming you are Ericson2314 on github, pointing you to this discussion</p>



<a name="211800809"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/global%20hooks%20and%20their%20relation%20to%20traits%20and%20vtables/near/211800809" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/global.20hooks.20and.20their.20relation.20to.20traits.20and.20vtables.html#211800809">(Sep 30 2020 at 18:24)</a>:</h4>
<p><span class="user-mention silent" data-user-id="239881">Josh Triplett</span> <a href="#narrow/stream/213817-t-lang/topic/global.20hooks.20and.20their.20relation.20to.20traits.20and.20vtables/near/211799108">said</a>:</p>
<blockquote>
<p>Concretely: if A depends on B, and B depends on C and D, then if C and D both "provide" the type there's a compile error, but B can override and say "here's the type" and then there's no compile error (as long as the type meets the defined trait constraints).</p>
</blockquote>
<p>In particular, I think that'd be important for crates that want to offer <em>defaults</em> without <em>mandating</em> a specific type.</p>



<a name="211800867"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/global%20hooks%20and%20their%20relation%20to%20traits%20and%20vtables/near/211800867" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jethro <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/global.20hooks.20and.20their.20relation.20to.20traits.20and.20vtables.html#211800867">(Sep 30 2020 at 18:25)</a>:</h4>
<p>yeah I fully agree a defaulting mechanism is missing from the RFC. this was discussed in the thread but not everyone agreed</p>



<a name="211800967"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/global%20hooks%20and%20their%20relation%20to%20traits%20and%20vtables/near/211800967" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/global.20hooks.20and.20their.20relation.20to.20traits.20and.20vtables.html#211800967">(Sep 30 2020 at 18:26)</a>:</h4>
<p>This is one of those times where I don't think we can just punt because there's no consensus.</p>



<a name="211801584"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/global%20hooks%20and%20their%20relation%20to%20traits%20and%20vtables/near/211801584" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jethro <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/global.20hooks.20and.20their.20relation.20to.20traits.20and.20vtables.html#211801584">(Sep 30 2020 at 18:31)</a>:</h4>
<p>as for the overriding, assuming crate C and D both export their types implementing the relevant trait, B could just <em>also</em> set the global. if the dependency tree only has a single node that (sets the global and covers all other setting of the global), the compiler could pick that</p>



<a name="211801722"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/global%20hooks%20and%20their%20relation%20to%20traits%20and%20vtables/near/211801722" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jethro <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/global.20hooks.20and.20their.20relation.20to.20traits.20and.20vtables.html#211801722">(Sep 30 2020 at 18:32)</a>:</h4>
<p>this may just be rephrasing what you were already thinking <span class="user-mention" data-user-id="239881">@Josh Triplett</span></p>



<a name="211801784"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/global%20hooks%20and%20their%20relation%20to%20traits%20and%20vtables/near/211801784" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/global.20hooks.20and.20their.20relation.20to.20traits.20and.20vtables.html#211801784">(Sep 30 2020 at 18:33)</a>:</h4>
<p><span class="user-mention" data-user-id="138938">@Jethro</span> Given a careful definition of "covers", I think I'd agree.</p>



<a name="211801812"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/global%20hooks%20and%20their%20relation%20to%20traits%20and%20vtables/near/211801812" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/global.20hooks.20and.20their.20relation.20to.20traits.20and.20vtables.html#211801812">(Sep 30 2020 at 18:33)</a>:</h4>
<p>I think it'd be reasonable to debate whether there should be a requirement to <em>declare</em> that you're overriding, though.</p>



<a name="211801832"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/global%20hooks%20and%20their%20relation%20to%20traits%20and%20vtables/near/211801832" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/global.20hooks.20and.20their.20relation.20to.20traits.20and.20vtables.html#211801832">(Sep 30 2020 at 18:33)</a>:</h4>
<p>I don't know if that'd help or just generate churn.</p>



<a name="211802012"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/global%20hooks%20and%20their%20relation%20to%20traits%20and%20vtables/near/211802012" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> John Ericson <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/global.20hooks.20and.20their.20relation.20to.20traits.20and.20vtables.html#211802012">(Sep 30 2020 at 18:34)</a>:</h4>
<p>/me is summoned.</p>



<a name="211802283"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/global%20hooks%20and%20their%20relation%20to%20traits%20and%20vtables/near/211802283" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> John Ericson <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/global.20hooks.20and.20their.20relation.20to.20traits.20and.20vtables.html#211802283">(Sep 30 2020 at 18:36)</a>:</h4>
<p>I might recommend you allplay around with an ML or Haskell's backpack to get a flavor of the design space. I am happy to offer advice on each, though I have backpack much more paged in at the moment.</p>



<a name="211802496"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/global%20hooks%20and%20their%20relation%20to%20traits%20and%20vtables/near/211802496" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jethro <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/global.20hooks.20and.20their.20relation.20to.20traits.20and.20vtables.html#211802496">(Sep 30 2020 at 18:38)</a>:</h4>
<p>I think people are fairly confident traits are the way to go</p>



<a name="211802556"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/global%20hooks%20and%20their%20relation%20to%20traits%20and%20vtables/near/211802556" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/global.20hooks.20and.20their.20relation.20to.20traits.20and.20vtables.html#211802556">(Sep 30 2020 at 18:39)</a>:</h4>
<p>Backpack seems like it's built more around the idea of parameterizable modules.</p>



<a name="211802567"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/global%20hooks%20and%20their%20relation%20to%20traits%20and%20vtables/near/211802567" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/global.20hooks.20and.20their.20relation.20to.20traits.20and.20vtables.html#211802567">(Sep 30 2020 at 18:39)</a>:</h4>
<p>Is that accurate?</p>



<a name="211805858"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/global%20hooks%20and%20their%20relation%20to%20traits%20and%20vtables/near/211805858" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> John Ericson <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/global.20hooks.20and.20their.20relation.20to.20traits.20and.20vtables.html#211805858">(Sep 30 2020 at 19:06)</a>:</h4>
<p>It is built more about that, but i would still give a it spin. I don't mean the say that the design should be more like that in the areas it already covers, but when thinking about the Cargo/composition/defaults side of things</p>



<a name="211826388"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/global%20hooks%20and%20their%20relation%20to%20traits%20and%20vtables/near/211826388" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jane Lusby <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/global.20hooks.20and.20their.20relation.20to.20traits.20and.20vtables.html#211826388">(Sep 30 2020 at 20:59)</a>:</h4>
<p>well if any movement starts happening on this I'd love to help</p>



<a name="211826482"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/global%20hooks%20and%20their%20relation%20to%20traits%20and%20vtables/near/211826482" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jane Lusby <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/global.20hooks.20and.20their.20relation.20to.20traits.20and.20vtables.html#211826482">(Sep 30 2020 at 20:59)</a>:</h4>
<p><span class="user-mention silent" data-user-id="116009">nikomatsakis</span> <a href="#narrow/stream/213817-t-lang/topic/global.20hooks.20and.20their.20relation.20to.20traits.20and.20vtables/near/211786327">said</a>:</p>
<blockquote>
<p>I feel like it would theoretically make a nice project group</p>
</blockquote>
<p>I'd definitely participate in such a group</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>